<template>
  <div class="app-container">
    <el-row :gutter="20">

        <el-card>
          <!--表格渲染-->
        <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
          <el-table-column :show-overflow-tooltip="true" prop="realName" label="姓名" />
          <el-table-column prop="realName" label="用户名" />
          <el-table-column prop="problemTypeInfo" label="问题类型" />
          <el-table-column prop="phone" label="电话" />
          <el-table-column prop="dsc" label="问题描述" />
          <el-table-column label="图片">
            <template slot-scope="scope">
              <div style="display:inline-block;" @click="setCurrentImage(item)" v-for="(item,index) in scope.row.picList || []" :key="index">
                {{ `图片${indeex+1}` }}
              </div>
            </template>
          </el-table-column>
        </el-table>
        </el-card>
        <!--分页组件-->
        <pagination />
    </el-row>
    <el-image :src="currentImage" :previewSrcList="[currentImage]" v-show="false"></el-image>
  </div>
</template>

<script>
import crudAdmin from '@/api/web/admin'
import CRUD, {
  presenter,
  header,
  form,
  crud
} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker'
export default {
  name: 'Admin',
  components: {
    crudOperation,
    rrOperation,
    udOperation,
    pagination,
    DateRangePicker
  },
  cruds() {
    return CRUD({
      title: '用户',
      url: 'api/user/problem/list',
      methodStr: 'post',
      dataStr: ['data', 'problemList'],
      optShow: {
        reset: false,
        othoer: true
      },
      crudMethod: { ...crudAdmin }
    })
  },
  mixins: [presenter(), header(), crud()],
  data() {
    // 自定义验证
    const validPhone = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入电话号码'))
      } else if (!isvalidPhone(value)) {
        callback(new Error('请输入正确的11位手机号码'))
      } else {
        callback()
      }
    }
    return {
      height: document.documentElement.clientHeight - 180 + 'px;',
      currentImage:'',
      defaultProps: {
        children: 'children',
        label: 'name',
        isLeaf: 'leaf'
      },
      permission: {
        add: ['admin', 'user:add'],
        edit: ['admin', 'article:edit'],
        del: ['admin', 'user:del']
      }
    }
  },
  mounted: function() {
    const that = this
    window.onresize = function temp() {
      that.height = document.documentElement.clientHeight - 180 + 'px;'
    }
  },
  methods: {
    setCurrentImage(item){
      this.currentImage = item
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  ::v-deep .vue-treeselect__control,
  ::v-deep .vue-treeselect__placeholder,
  ::v-deep .vue-treeselect__single-value {
    height: 30px;
    line-height: 30px;
  }

  .n_avatar {
    max-width: 120px;
    max-height: 120px;
  }
  .btn{
    margin: 0;
  }
</style>
